package com.zj.study.config;

import io.netty.util.concurrent.DefaultThreadFactory;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <p>异步线程池配置<p/>
 *
 * @author 赵赳
 * @since 2021/11/15 17:15
 */
@Configuration
public class ThreadPoolConfig {

  private static final int corePoolSize = 8;
  private static final int maximumPoolSize = 100;
  private static final Long keepAliveTime = 5L;

  //全局线程池配置
  //@Bean
  public ThreadPoolExecutor threadPool() {
    return new ThreadPoolExecutor(corePoolSize,
        maximumPoolSize,
        keepAliveTime,
        TimeUnit.SECONDS,
        new ArrayBlockingQueue<>(256),
        new DefaultThreadFactory("UnFreeze"),
        new ThreadPoolExecutor.CallerRunsPolicy());
  }

}
